package com.community.zhihuishequ.view.base;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/12/22 0022.
 */

public class BasePageAdapter extends FragmentPagerAdapter {

    private List<BaseListFragment> mFragmentList = null;

    private String[] titles;

    public BasePageAdapter(FragmentManager fragmentManager, List<BaseListFragment> fragments, String[] titles) {
        super(fragmentManager);
        this.mFragmentList = fragments;
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment;
        if (position < mFragmentList.size()) {
            fragment = mFragmentList.get(position);
        } else {
            fragment = mFragmentList.get(0);
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (titles != null && titles.length > 0) {
            return titles[position];
        } else {
            return null;
        }
    }
}